#include "swagme.h"
#include "Swag.h"

const int Swag::FrameCount = 2;
const int Swag::speed = 2;

Swag::Swag(char *file, int x, int y)
  : Facing(sm_dir_right), prevFacing(sm_dir_right), FrameCounter(0),
    mpSprite(new Sprite(file)), posX(x), posY(y), prevX(x), prevY(y) {
}
    
Swag::Swag(const char *file)
: Facing(sm_dir_right), prevFacing(sm_dir_right), FrameCounter(0),
  mpSprite(new Sprite(file)), posX(0), posY(0), prevX(0), prevY(0) {

}

Swag::Swag()
: Facing(sm_dir_right), prevFacing(sm_dir_right), FrameCounter(0),
  mpSprite(NULL), posX(0), posY(0), prevX(0), prevY(0) {

}

void Swag::Init(char *file, int x, int y)  {
  if (mpSprite) delete mpSprite;
  mpSprite = new Sprite(file);
  posX=x;
  posY=y;
}

int Swag::Draw(SDL_Surface *dst) {
  int r, frameNum ;

  if (++FrameCounter > 64) FrameCounter = 0;
  frameNum = FrameCounter /32; // TODO: this is an ugly hack, need a proper central animation timer

  // mpSwagPenSprite->Draw(0, ((penFrame/32)%2),mpDisplay->getScreen(), 78+MAP_POS_X, 78+MAP_POS_Y);

  // cout << "x " << posX << " y " << posY << endl;
  return mpSprite->Draw(0, frameNum,dst, posX+MAP_POS_X, posY+MAP_POS_Y);
}

Swag::~Swag() {
  if (mpSprite) delete mpSprite;
}
